<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<div id="nifi-registry-import-new-flow-dialog"
     xmlns:width="http://www.w3.org/1999/xhtml">
    <div class="pad-bottom-md" fxLayout="row" fxLayoutAlign="space-between center">
        <mat-card-title class="ellipsis">
            Import New Flow
        </mat-card-title>
        <button mat-icon-button (click)="cancel()">
            <mat-icon color="primary">close</mat-icon>
        </button>
    </div>
    <div id="new-flow-container">
        <div class="fill-available-width">
            <div class="pad-bottom-sm label-name">
                <label>Flow Name</label>
            </div>
            <div id="flow-name" fxLayout="row" fxLayoutAlign="space-between center" class="push-bottom-md">
                <div id="new-flow-name-input" class="fill-available-width">
                    <input
                        #flowName
                        id="new-flow-name-input-field"
                        class="pad-bottom-md fill-available-width"
                        matInput
                        type="text"
                        placeholder="Create a unique name"
                        [(ngModel)]="name"/>
                </div>
                <div class="version-count">
                    <span>v.1</span>
                </div>
            </div>
        </div>
        <div class="pad-bottom-sm label-name">
            <label class="pad-bottom-sm">Flow Description</label>
        </div>
        <div id="new-flow-description" fxLayout="row" class="pad-bottom-xs fill-available-width">
            <textarea class="push-bottom-md" [(ngModel)]="description"></textarea>
        </div>
        <div class="pad-bottom-sm label-name">
            <label>Bucket</label>
        </div>
        <div class="fill-available-width bucket-dropdown-field pad-bottom-xs">
            <mat-form-field appearance="fill" floatLabel="always" fxFlex>
                <mat-select #bucketSelect panelClass="bucket-dropdown-select" placeholder="Choose a location" [(value)]="activeBucket">
                    <mat-option *ngFor="let bucket of writableBuckets" [value]="bucket.identifier">
                        {{bucket.name}}
                    </mat-option>
                </mat-select>
            </mat-form-field>
        </div>
        <div id="new-flow-file-upload-message-container" fxLayout="row" fxLayoutAlign="space-between center">
            <div class="label-name">
                <label>Flow Definition</label>
            </div>
            <ng-container *ngIf="fileToUpload != null && !hoverValidity || hoverValidity === 'valid'">
                <span class="file-upload-message">
                    Looks good!
                    <i class="fa fa-check-circle-o" aria-hidden="true"
                       style="color: #1eb475;"></i>
                </span>
            </ng-container>
            <ng-container *ngIf="hoverValidity === 'invalid'">
                <span class="file-upload-message">
                    File format is not valid
                    <i class="fa fa-times-circle" aria-hidden="true"
                       style="color: #ef6162;"></i></span>
            </ng-container>
        </div>
        <div id="new-flow-definition"
             class="fill-available-width pad-bottom-sm"
             fxLayout="row"
             fxLayoutAlign="space-between center"
             (click)="selectFile()"
             (dragenter)="fileDragHandler($event, extensions)"
             (dragover)="fileDragHandler($event, extensions)"
             (dragend)="fileDragEndHandler()"
             (dragleave)="fileDragEndHandler()"
             (drop)="fileDropHandler($event)">
            <mat-form-field floatLabel="never" flex>
                <input matInput
                       id="new-flow-definition-input"
                       class="ellipsis"
                       type="text"
                       autocomplete="off"
                       placeholder="Drop file or select..."
                       [value]="fileName"
                       [ngClass]="{'file-hover-valid': (hoverValidity === 'valid'),
                       'file-hover-error': (hoverValidity === 'invalid'),
                       'file-selected': (fileToUpload != null), 'multiple': multiple}"/>
                <div class="icon" id="select-flow-file-button">
                    <i class="fa fa-upload" aria-hidden="true"></i>
                    <span>Select file</span>
                </div>
                <div id="new-flow-file-upload-form-container">
                    <form id="new-flow-file-upload-form" enctype="multipart/form-data" method="post">
                        <input id="upload-flow-file-field"
                               type="file"
                               name="file"
                               [accept]="extensions"
                               (change)="handleFileInput($event.target.files)"/>
                    </form>
                </div>
            </mat-form-field>
        </div>
    </div>
</div>
<div fxLayout="row">
    <span fxFlex></span>
    <button (click)="cancel()" color="fds-regular" mat-raised-button
            i18n="Cancel new flow definition import|A button for cancelling the new flow definition to import in the registry.">
        Cancel
    </button>
    <button [disabled]="!fileToUpload || !flowName.value || !bucketSelect.value" class="push-left-sm" data-automation-id="import-new-flow-button"
            (click)="importNewFlow()"
            color="fds-primary" mat-raised-button
            i18n="Cancel new flow definition import|A button for cancelling the new flow definition to import in the registry.">
        Import
    </button>
</div>
